package jtk.project4.fleet.ibatis.dao;

import java.sql.SQLException;
import java.util.List;

import jtk.project4.fleet.domain.Lists;
import jtk.project4.fleet.domain.PartHist;
import jtk.project4.fleet.domain.Vendor;

public class PartHistDao extends IbatisDao{

	public PartHist selectPartHist(int id) throws SQLException {
		return (PartHist) getSqlMap().queryForObject("SELECT_PARTHIST_BY_ID", id);
	}
	
	public List selectPartHists() throws SQLException {
		List selectPartHists = null;
		selectPartHists =getSqlMap().queryForList("SELECT_ALL_PARTHIST", null);
		return selectPartHists;
	}
	
	public PartHist insertPartHists(PartHist partHist) throws SQLException{
		return (PartHist) getSqlMap().insert("INSERT_PARTHIST", partHist);
	}
	
	public int updatePartHists(PartHist partHist) throws SQLException{
		return (int) getSqlMap().update("UPDATE_PARTHIST", partHist);
	}
	
	public int deletePartHists(PartHist partHist) throws SQLException{
		return (int) getSqlMap().delete("DELETE_PARTHIST", partHist);
	}
	
	public static void main (String args[]) throws SQLException{
		PartHist partHist;
		List<PartHist> partHists;		
		partHist = new PartHist();
		//untuk select by id
		/*
		partHist = new PartHistDao().selectPartHist(239);
		System.out.println("PartHist dengan nama ="+partHist.getName()+ " ,telah di dapat pada dari DB dengan id ="+ partHist.getPartHistId());
		*/
		
		//untuk select semua
		/*
		partHists = new PartHistDao().selectPartHists();
		System.out.println(partHists.size());		
		*/
		
		//untuk insert
		/*
		partHist.setName("coba tes saya");
		new PartHistDao().insertVendor(partHist);
		*/
		
		//UPDATE
		/*
		partHist = new PartHistDao().selectPartHist(251);
		partHist.setName("UPDATE NAMEd"); 
		new PartHistDao().updatePartHists(partHist);
		System.out.println("update vendor dengan nama ="+partHist.getName()+ " ,telah diupdate"); 
		*/
		partHist.setPartHistId(251);
		new PartHistDao().deletePartHists(partHist);
	}
}
